package com.open.capacity.task.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.SysTask;
import com.open.capacity.common.web.CodeEnum;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.task.dao.TaskReplyDao;
import com.open.capacity.task.dto.TaskReplyCommentDto;
import com.open.capacity.task.model.TaskReplyAndComment;
import com.open.capacity.task.service.TaskReplyService;
import com.open.capacity.task.utils.Commons;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class TaskReplyServiceImpl extends ServiceImpl<TaskReplyDao, TaskReplyAndComment> implements TaskReplyService {
    @Resource
    private TaskReplyDao taskReplyDao;

    @Override
    public PageResult findCommnet(Map<String, Object> params) {
        try {
            List<TaskReplyCommentDto> commentList = baseMapper.selectCommentByCondition(params);
            PageInfo<TaskReplyCommentDto> pageInfo = new PageInfo<>(Commons.fillCommentChildren(commentList));
            return PageResult.<TaskReplyCommentDto>builder().code(CodeEnum.SUCCESS.getCode()).count(pageInfo.getTotal()).data(pageInfo.getList()).build();
        } catch (Exception e) {
            log.warn(e.getMessage());
            throw new ServiceException(e);
        }
    }
}
